CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
ADD_LIBRARY(trax_client SHARED client.cpp process.cpp threads.cpp timer.cpp)
ADD_LIBRARY(trax_client_static STATIC client.cpp process.cpp threads.cpp timer.cpp)
TARGET_COMPILE_OPTIONS(trax_client_static PUBLIC -DTRAX_STATIC_DEFINE)
TARGET_LINK_LIBRARIES(trax_client trax)
INSTALL(FILES "include/trax/client.hpp" DESTINATION include/trax)
SET_TARGET_PROPERTIES(trax_client PROPERTIES VERSION ${BUILD_VERSION} SOVERSION 0)
SET_TARGET_PROPERTIES(trax_client_static PROPERTIES POSITION_INDEPENDENT_CODE TRUE)

# On older linux distributions, we need to explicitly link against librt
# in order to get clock_gettime() in timer.cpp
IF (UNIX AND NOT APPLE)
	TARGET_LINK_LIBRARIES(trax_client -lrt)
ENDIF()

ADD_EXECUTABLE(traxclient cli.cpp getopt.c)
TARGET_LINK_LIBRARIES(traxclient trax_client)

ADD_EXECUTABLE(traxtest tester.cpp tester_resources.c getopt.c)
TARGET_LINK_LIBRARIES(traxtest trax_client)

IF (BUILD_OPENCV)
	ADD_DEFINITIONS(-DTRAX_BUILD_OPENCV)
  	TARGET_LINK_LIBRARIES(traxclient trax_opencv ${OpenCV_LIBS})
	ADD_EXECUTABLE(traxplayer player.cpp getopt.c )
	TARGET_LINK_LIBRARIES(traxplayer trax_opencv trax_client ${OpenCV_LIBS})
	INSTALL(TARGETS traxplayer RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
ENDIF (BUILD_OPENCV)

IF (WIN32 OR WIN64)
	INSTALL(TARGETS trax_client EXPORT client
		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
	INSTALL(TARGETS traxtest traxclient
		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
ELSE ()
	INSTALL(TARGETS trax_client EXPORT client RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
	INSTALL(TARGETS traxclient traxtest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
ENDIF()

INSTALL(EXPORT client DESTINATION ${CONFIG_INSTALL_DIR} FILE trax-component-client.cmake)

